// pages/refundApply/refundApply.js
import * as API_Mall_Order from '../../../api/mall/order'
import * as API_Dict from '../../../api/dict'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    order:{},
    cause:[],
    causeIndex:0,
    refund:{
      cause:'',
      orderId:''
    },
    commitState:true
  },

  changeCause(e){
    let item = this.data.cause[e.detail.value]
    this.setData({
      causeIndex: e.detail.value,
      'refund.cause':item.dictLabel
    })
  },
  apply(e){
    API_Mall_Order.refundApply(this.data.refund).then(res=>{
      console.log(res)
      if(res.code == 200){
        var page = getCurrentPages();
        var prevPage = page[page.length - 3]
        wx.navigateBack({
          delta: 2,
          success(e){
            prevPage.flush()
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    API_Mall_Order.getOrderDetail(options.orderId).then(res=>{
      if(res.data){
          this.setData({
            order:res.data,
            'refund.orderId':options.orderId
          })
         API_Dict.getDictData('mall_product_refund_cause').then(res=>{
           that.setData({
            cause:res,
            'refund.cause':res[0].dictLabel
           })
         })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})